package com.example.demo08;

import java.util.Map;

import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.hardware.usb.UsbAccessory;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbManager;
import android.os.Bundle;
import android.view.View;

public class UsbPage extends BaseTextPage {

	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		super.onViewCreated(view, savedInstanceState);
		
		UsbManager um = (UsbManager) getActivity().getSystemService(Context.USB_SERVICE);
		Map<String, UsbDevice> map = um.getDeviceList();
		if(map != null && !map.isEmpty()) {
			for(Map.Entry<String, UsbDevice> e : map.entrySet()) {
				appendn(e.getKey() + ": " + e.getValue());
			}
		} else
			appendn("NO USB DEVICE");
		
		UsbAccessory[] as = um.getAccessoryList();
		if(as != null && as.length > 0) {
			for(UsbAccessory a : as) 
				appendn("UsbAccessory: " + a);
		} else
			appendn("NO UsbAccessory");
		
		BluetoothAdapter ba = BluetoothAdapter.getDefaultAdapter();
		appendn("bt_name: " + ba.getName());
		appendn("bt_addr: " + ba.getAddress());
			
		
		update();
	}
}
